package com.umgsai.thread.thread66;

//递归与非递归取组内对象
public class Main5 {
	public static void main(String[] args) {
		ThreadGroup mainGroup = Thread.currentThread().getThreadGroup();
		ThreadGroup groupA = new ThreadGroup(mainGroup, "A");
		Runnable runnable = new Runnable() {
			
			@Override
			public void run() {
				try {
					System.out.println("run Method");
					Thread.sleep(10000);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		};
		ThreadGroup groupB = new ThreadGroup(groupA, "B");
		ThreadGroup[] groups = new ThreadGroup[Thread.currentThread().getThreadGroup().activeGroupCount()];
		//传入true取得其子组及子孙组
		Thread.currentThread().getThreadGroup().enumerate(groups, true);
		for (int i = 0; i < groups.length; i++) {
			if (groups[i] != null) {
				System.out.println(groups[i].getName());
			}
		}
		System.out.println("------");
		ThreadGroup[] groups2 = new ThreadGroup[Thread.currentThread().getThreadGroup().activeGroupCount()];
		Thread.currentThread().getThreadGroup().enumerate(groups2, false);
		for (int i = 0; i < groups2.length; i++) {
			if (groups2[i] != null) {
				System.out.println(groups2[i].getName());
			}
			
		}
	}
}
